<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2019/9/12
 * Time: 15:58
 */

namespace app\admin\controller;


use think\Db;
use think\Request;

class Agreement extends Base
{
    /**
     * 老师端用户协议
     * @return mixed|\think\response\Json
     */
    public function teacherAgreement(){
        if(Request::instance()->isPost()){
            $content = input('about_teacher_agreement');
            $res = Db::table('up_about')
                ->where('about_id', 9)
                ->update(['about_teacher_agreement' => $content]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about')->where('about_id', 9)->value('about_teacher_agreement');
        $this->assign('agreement', $agreement);
        return $this->fetch('agreement/teacheragreement');
    }
    
    /**
     * 学生端用户协议
     * @return mixed|\think\response\Json
     */
    public function studentAgreement(){
        if(Request::instance()->isPost()){
            $content = input('about_student_agreement');
            $res = Db::table('up_about')
                ->where('about_id', 8)
                ->update(['about_student_agreement' => $content]);
            if($res){
                return json(['code' => 200, 'msg' => '保存成功']);
            }else{
                return json(['code' => 100, 'msg' => '保存失败']);
            }
        }
        $agreement = Db::table('up_about')->where('about_id', 8)->value('about_student_agreement');
        $this->assign('agreement', $agreement);
        return $this->fetch('agreement/studentagreement');
    }
    
    /**
     * 联系我们
     * @return mixed|\think\response\Json
     */
    public function service(){
        if(Request::instance()->isPost()){
            $phone = input('phone');
            $res = Db::table('up_about')->where('about_id', 7)->setField('about_phone', $phone);
            if($res){
                return json(['code' => 200, 'msg' => '编辑成功']);
            }else{
                return json(['code' => 100, 'msg' => '编辑失败']);
            }
        }
        $phone = Db::table('up_about')->where('about_id', 7)->value('about_phone');
        $this->assign('phone', $phone);
        return $this->fetch('agreement/service');
    }
}